/*********************************************************************\
*
*                  (c) lkc
*                  All Rights Reserved. lkc Confidential
*
\*********************************************************************/
/*********************************************************************\
*   Title                      :
*
*   Module Description         :
*
*   Author                     : lkc
*
*   Created                    : 2018-6-24
*
\*********************************************************************/
#ifndef PROTOCOL_PC_H
#define PROTOCOL_PC_H

#include "Communicate.h"
#ifdef PC_IS_ALIVE
#ifdef PC_COMM_TYPE_IS_QT
#include <QObject>
#include "ProtocolBaseQt.h"
class ProtocolPC : public QObject, public ProtocolBaseQt
{
    Q_OBJECT
#else
#include "ProtocolBasePosix.h"
class ProtocolPC : public ProtocolBasePosix
{
#endif //#ifdef PC_COMM_TYPE_IS_QT
public:
    static ProtocolPC& GetInstance() {return m_Instance;}//获取实例
    ProtocolPC& operator = (const ProtocolPC&) = delete;
    ProtocolPC(const ProtocolPC&) = delete;
private:
    static ProtocolPC m_Instance;
    ProtocolPC() {}//因为ProtocolPC(const ProtocolPC&) = delete;所以ProtocolPC() {}必须显示定义
public:
    void ExtractData(const unsigned char *data, int nLength) override;
    int CycleSendOnce() override;
private:
    void EventReceiveFrameParse();
//    int GetCycleTimeMS() override {return 40;}
    int GetOutModeInt();//图像模式0--原图输出 1--增强输出模式 2--信息叠加模式
    void SelfCheckParse();
    void GainParse();
    void FoucsParse();
    void ContrastParse();
    void OutModeParse();
    void WorkModeParse();
    void RecordParse();
    void CrossParse();
    int SendFrame();
    void BuildFrame();
protected:
    int GetCycleTimeMS() override {return 40;}
private:
    const static int FRAME_LENGTH_RECEIVE = 7;
    const static int FRAME_LENGTH_EVENT_SEND = 8;
    const static unsigned char HEAD1 = 0xE1;
    const static unsigned char HEAD2_EVENT = 0x00;    
    const static unsigned char END = 0xFB;
    const static unsigned char HEAD2_CYCLE = 0x01;
    const static unsigned char NORMAL_CYCLE = 0x00; //数据有效性 0x00 正常状态 0x01 异常状态
    const static unsigned char ABNORMAL_CYCLE = 0x01;//数据有效性 0x01 异常状态
    const static unsigned char RESULT_SUCCESS = 0x01;
    const static unsigned char RESULT_FAIL = 0x02;
    unsigned char m_funcCodeSend;
    unsigned char m_commandSend;
    unsigned char m_dataSend;
    unsigned char m_resultSend;
    unsigned char m_frameToSend[FRAME_LENGTH_EVENT_SEND];
    unsigned char m_funcCodeReceive;
    unsigned char m_commandReceive;
    unsigned char m_dataReceive;
};
#endif //#ifdef PC_IS_ALIVE
#endif // PROTOCOL_PC_H

/********************************************************************\
 *
 * REVISION RECORDS
 *
\*********************************************************************/
/*********************************************************************/
/*
 *
 *
 *
\*********************************************************************/
/*------------------------------The End------------------------------*/
